package com.situ.mall.controller;

import com.situ.common.util.PageResult;
import com.situ.common.util.Result;
import com.situ.mall.pojo.entity.Collect;
import com.situ.mall.pojo.entity.User;
import com.situ.mall.pojo.query.CollectQuery;
import com.situ.mall.service.ICollectService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/collect")
public class CollectController {
    @Autowired
    private ICollectService collectService;

    @RequestMapping("/addCollect")
    public Result addCollect(Collect collect, HttpSession session) {
        User user = (User) session.getAttribute("user");
        Integer userId = user.getId();
        collect.setUserId(userId);
        collectService.addCollect(collect);
        return Result.ok("收藏成功！");
    }
    @RequestMapping("/cancelCollect")
    public Result cancelCollect(Collect collect, HttpSession session) {
        User user = (User) session.getAttribute("user");
        Integer userId = user.getId();
        collect.setUserId(userId);
        collectService.cancelCollect(collect);
        return Result.ok("取消收藏！");
    }
    @RequestMapping("/checkCollect")
    public Result checkCollect(Collect collect, HttpSession session) {
        User user = (User) session.getAttribute("user");
        Integer userId = user.getId();
        collect.setUserId(userId);
        Collect checkCollect = collectService.checkCollect(collect);
        return Result.ok(checkCollect);
    }
    @RequestMapping("/collectList")
    public PageResult collectList(CollectQuery collectQuery, HttpSession session) {
        User user = (User) session.getAttribute("user");
        Integer userId = user.getId();
        collectQuery.setUserId(userId);
        PageResult pageInfo = collectService.collectList(collectQuery);
        return pageInfo;
    }
    @RequestMapping("/deleteCollect")
    public Result deleteCollect(Integer id) {
        collectService.deleteCollect(id);
        return Result.ok("取消收藏成功！");
    }
}
